package com.jiang.myfm.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiang.myfm.R;
import com.jiang.myfm.adapters.DownloadAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/2.
 */
public class Downfragment extends Fragment {

    private TabLayout mDownTabLayout;
    private TextView mDownStorageSizeTextView;

    private ViewPager mViewPager;
    private List<Fragment> mFragmentList;

    public Downfragment() {
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View ret = inflater.inflate(R.layout.fragment_down, container, false);
        //初始化view
        initView(ret);
        //初始化tab
        initTab();
        //初始化数据
        initData();
        initViewPager();
        return ret;
    }

    private void initViewPager() {
        mFragmentList = new ArrayList<>();
        DownAlbumFragment downAlbumFragment = new DownAlbumFragment();
        DownVoiceFragment downVoiceFragment = new DownVoiceFragment();
        DownDownloadFragment downDownloadFragment = new DownDownloadFragment();
        mFragmentList.add(downAlbumFragment);
        mFragmentList.add(downVoiceFragment);
        mFragmentList.add(downDownloadFragment);
        DownloadAdapter adapter=new DownloadAdapter(getFragmentManager(),mFragmentList);
        mViewPager.setAdapter(adapter);
        mDownTabLayout.setupWithViewPager(mViewPager);
    }

    private void initData() {


    }

    private void initTab() {
        String[] tabStr = getResources().getStringArray(R.array.tabstr);
        for (int i = 0; i < tabStr.length; i++) {
            TabLayout.Tab tab = mDownTabLayout.newTab();
            tab.setText(tabStr[i]);
            mDownTabLayout.addTab(tab);
        }
        mDownTabLayout.setSelectedTabIndicatorColor(Color.RED);
        mDownTabLayout.setTabTextColors(Color.GRAY, Color.RED);
    }

    private void initView(View ret) {
        mDownTabLayout = (TabLayout) ret.findViewById(R.id.down_tab);
        mDownStorageSizeTextView = (TextView) ret.findViewById(R.id.down_storage_size_text_view);
        mViewPager = (ViewPager) ret.findViewById(R.id.down_viewpager_download);
    }

}
